//
//  MediaTableViewCell.m
//  LPSNews
//
//  Created by lanou3g on 14-10-20.
//  Copyright (c) 2014年 LPS. All rights reserved.
//

#import "MediaTableViewCell.h"
#import "UIImageView+WebCache.h"

@implementation MediaTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //底部视图
        UIView * bottomView = [[UIView alloc]init];
        self.bottomView = bottomView;
        [self.contentView addSubview:bottomView];
        [bottomView release];
        //封面
        UIImageView * mediaImageView = [[UIImageView alloc]init];
        self.mediaImageView = mediaImageView;
        [self.bottomView addSubview:mediaImageView];
        [mediaImageView release];
        //标题
        UILabel * titleLabel = [[UILabel alloc]init];
        self.titleLabel = titleLabel;
        titleLabel.font = [UIFont systemFontOfSize:14];
        [self.bottomView addSubview:titleLabel];
        [titleLabel release];
        //时长
        UILabel * timeLabel = [[UILabel alloc]init];
        self.timeLabel = timeLabel;
        [self.bottomView addSubview:timeLabel];
        [timeLabel release];
        //封面上图标
        UIImageView * startImageView = [[UIImageView alloc]init];
        self.startImageView = startImageView;
        [self.bottomView addSubview:startImageView];
        [startImageView release];
        //时长
        UIImageView * iconImageView = [[UIImageView alloc]init];
        self.iconImageView = iconImageView;
        [self.bottomView addSubview:iconImageView];
        [iconImageView release];
 
    }
    return self;
}
- (void)setMedia:(VideoPlayer *)media
{
    //底部视图
    self.bottomView.frame = CGRectMake(10, 0, 300,240);
    self.bottomView.layer.borderWidth = 0.4;
    self.bottomView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    //图片
    self.mediaImageView.frame = CGRectMake(0,0,300,180);
    [self.mediaImageView sd_setImageWithURL:[NSURL URLWithString:media.cover] placeholderImage:[UIImage imageNamed:@"placeholderImage"] options:SDWebImageProgressiveDownload];
    self.startImageView.frame = CGRectMake(130,70,40,40);
    self.startImageView.image = [UIImage imageNamed:@"video_list_cell_big_icon"];
    //底部视图
    //标题
    self.titleLabel.frame = CGRectMake(10,CGRectGetMaxY(self.mediaImageView.frame)+5,280,20);
    self.titleLabel.text = media.title;
    //图标
    self.iconImageView.frame =  CGRectMake(10,CGRectGetMaxY(self.titleLabel.frame)+5,20,20);
    self.iconImageView.image = [UIImage imageNamed:@"video_list_cell_icon"];
    //时长
    self.timeLabel.frame = CGRectMake(CGRectGetMaxX(self.iconImageView.frame)+5,CGRectGetMaxY(self.titleLabel.frame)+8,80,15);
    self.timeLabel.text = [NSString stringWithFormat:@"%.2d:%.2d",(int)media.length/60,(int)media.length%60];
    self.timeLabel.font = [UIFont systemFontOfSize:12];

}
- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
